package com.common.activity;

import java.lang.reflect.Field;

import android.app.Activity;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;

import com.common.StarAppConfig;
import com.flurry.android.FlurryAgent;
import com.product.android.ui.activity.BaseReceiverFragmentActivity;

/**
 * 明星App Activity基类
 * 
 * <br>
 * Created 2014-5-13 下午7:13:23
 * 
 * @version
 * @author HuangYK
 * 
 * @see
 */
public class StarAppBaseFramentActivity extends BaseReceiverFragmentActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	};

	@Override
	public void onResume() {
		super.onResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	protected void onStart() {
	    super.onStart();
        FlurryAgent.onStartSession(this, StarAppConfig.getConfig(StarAppConfig.CONFIG_FLURRY_APPLICATION_KEY));
	}
	
	@Override
	protected void onStop() {
		super.onStop();
        FlurryAgent.onEndSession(this);
	}

	/**
	 * 开启硬件加速
	 * 
	 * <br>
	 * Created 2014-6-13 上午10:59:01
	 * 
	 * @param act
	 *            activity对象
	 * @author : HuangYK
	 */
	public static void openGpu(Activity act) {
		if (Build.VERSION.SDK_INT < VERSION_CODES.ICE_CREAM_SANDWICH) {
			return;
		}

		if (act == null || act.getWindow() == null
				|| act.getWindow().getAttributes() == null) {
			return;
		}

		try {
			WindowManager.LayoutParams lp = act.getWindow().getAttributes();
			Field field = lp.getClass().getField("FLAG_HARDWARE_ACCELERATED");
			int flag_hardware_accelerated = field.getInt(lp);
			act.getWindow().addFlags(flag_hardware_accelerated);
		} catch (Exception ex) {
			Log.e("openGpu Exception", ex.toString());
			return;
		}
	}
}
